package com.thread.other;

import java.util.concurrent.TimeUnit;

public class InnerClassRunnable2 {

	private int countDown = 5;
	private Thread t;

	// 使用匿名内部类
	public InnerClassRunnable2(String name) {
		t = new Thread(new Runnable() {

			public void run() {
				while (true) {
					System.out.print(this + ",");
					if (--countDown == 0) {
						return;
					}
					try {
						TimeUnit.MILLISECONDS.sleep(10);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}

			public String toString() {
				return Thread.currentThread().getName() + ": " + countDown;
			}

		}, name);
		t.start();
	}

	public static void main(String[] args) {
		InnerClassRunnable2 in = new InnerClassRunnable2("InnerClassRunnable2");
	}

}
